import { get, httpRequest, post } from '@/http/request'
import { params } from '@/types/common'
import { deptListItem, deptTreeItem } from '@/types/dept'
import { postFetch, putFetch } from './common'
/** 获取所有的部门信息 - tree*/
export const getDeptListAllService = (data: params = {}) => {
  return postFetch<deptListItem[] | deptTreeItem[]>('/department/getAll', data)
}
/**增加部门信息 */
export const addDeptService = (data) => {
  return postFetch('/department/add', data, { noCache: true, clearCache: ['/department/getAll', '/department/list'] })
}

/**删除部门信息 */
export const deleteDeptService = (ids: number[]) => {
  return httpRequest({
    url: '/department/delete',
    method: 'delete',
    data: { ids },
  })
}
/** 更新部门信息 */
export const updateDeptService = (data) => {
  return putFetch('/department/update', data, { noCache: true, clearCache: ['/department/getAll', '/department/list'] })
}
/**
 * 更新部门启用状态-下属部门一起修改
 */
export const updateDeptStatusService = (id: string, status: number) => {
  return post('/department/updateStatus', { id, status })
}
